# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Robin Broda <coderobe @ archlinux.org>
# Contributor: Peter Wu <peter@lekensteyn.nl>
# Contributor: Evaggelos Balaskas <eblaskas _AT_ ebalaskas _DOT_ gr>
# Contributor: Xiao-Long Chen <chenxiaolong@cxl.epac.to>
# Contributor: Nikos Skalkotos <skalkoto (at) Gmail.com>

pkgname=libguestfs
pkgver=1.48.6
pkgrel=5
pkgdesc="Access and modify virtual machine disk images"
arch=(loong64 x86_64)
url="https://libguestfs.org/"
license=(GPL2 LGPL2.1)
# NOTE: see appliance/packagelist.in
_appliancedeps=(
  btrfs-progs
  debootstrap
  dhcpcd
  dosfstools
  exfatprogs
  f2fs-tools
  gptfdisk
  grub
  iproute2
  iputils
  jfsutils
  libldm
  lrzip
  lsof
  lsscsi
  lvm2
  lzop
  mdadm
  mtools
  multipath-tools
  nilfs-utils
  ntfs-3g
  openssh
  pciutils
  procps-ng
  psmisc
  reiserfsprogs
  rsync
  squashfs-tools
  strace
  syslinux
  systemd-sysvcompat
  vim
  xfsprogs
  yara
)
depends=(
  augeas
  fuse2
  hivex
  jansson
  sleuthkit
  libconfig
  libvirt
  perl-libintl-perl
  qemu
  supermin
  "${_appliancedeps[@]}"
)
makedepends=(
  bash-completion
  cdrtools
  cpio
  erlang-nox
  ghc
  go
  gobject-introspection
  gperf
  ocaml
  ocaml-compiler-libs
  ocaml-findlib
  perl-module-build
  python
  java-environment
  lua
  php
  ruby
  ruby-rake
  ruby-rdoc
  rust
  vala
)
checkdepends=(linux ruby-test-unit)
optdepends=(
  'gobject-introspection: GObject-Introspection Bindings'
  'java-runtime: for Java bindings'
  'ocaml: OCaml Bindings'
  'php: for PHP module'
  'python: Python Bindings'
  'ruby: for Ruby bindings'
)
provides=(libguestfs.so libguestfs-gobject-1.0.so)
backup=(etc/libguestfs-tools.conf)
source=(
  http://download.libguestfs.org/${pkgver%.*}-stable/$pkgname-$pkgver.tar.gz{,.sig}
  $pkgname-1.48.1-disable_php_tests.patch
)
sha256sums=('0c03cdb2f3460fa492e8423a003e3aa7d51a1311906e01467d1fb90ebf336ac5'
            'SKIP'
            '151d7ab43e7150c7d645eb0bad9681ce5ecc59cae44f254f08ef617ce3d9932f')
b2sums=('22359ed4b55e29f985dbbbc4f0337eaec32f21a1413bd778656c3f0270891bec520a0b9590e104836eaf9367aeb9ac681b0bf85852fb7a2059da3f7062bc5111'
        'SKIP'
        '2f7c429875d80b2b3a70286f83764ce6ed8be86055232fc059ab55ebf8393f9d29a2241401c7ab55af7ba9180ea85909647fe06ca51880f93bc66b488bcec78c')
validpgpkeys=('F7774FB1AD074A7E8C8767EA91738F73E1B768A0') # Richard W.M. Jones <rjones@redhat.com>

prepare() {
  # disable php tests, as missing arginfo definition makes them fail: https://github.com/libguestfs/libguestfs/issues/78
  patch -Np1 -d $pkgname-$pkgver -i ../$pkgname-1.48.1-disable_php_tests.patch

  cd $pkgname-$pkgver
  autoreconf -fiv
}

build() {
  cd $pkgname-$pkgver
  # TODO: build haskell bindings
  CFLAGS+=" -ffat-lto-objects" \
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --sbindir=/usr/bin \
    --disable-static \
    --disable-haskell \
    --with-extra-packages="libldm systemd-sysvcompat openssh qemu" \
    --with-guestfs-path=/usr/lib/guestfs

  make
}

check() {
  LIBGUESTFS_TRACE=1 make -k check -C $pkgname-$pkgver
}

package() {
  make INSTALLDIRS=vendor DESTDIR="$pkgdir" install -C $pkgname-$pkgver
}
